package com.mzj.saas.rent;

import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.core.BaseController;
import com.haixiaoke.saas.repository.core.page.TableDataInfo;
import com.haixiaoke.saas.repository.pojo.ApartmentItemRuleRef;
import com.haixiaoke.saas.repository.service.IApartmentItemRuleRefService;
import com.mzj.saas.util.LoginUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 账单规则与收费项目关系Controller
 *
 * @author qixi
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/business/ref")
public class ApartmentItemRuleRefController extends BaseController {
    @Autowired
    private IApartmentItemRuleRefService apartmentItemRuleRefService;
    @Autowired
    private LoginUserUtil loginUserUtil;

    /**
     * 查询账单规则与收费项目关系列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ApartmentItemRuleRef apartmentItemRuleRef) {
        startPage();
        List<ApartmentItemRuleRef> list = apartmentItemRuleRefService.selectApartmentItemRuleRefList(apartmentItemRuleRef);
        return getDataTable(list);
    }

    /**
     * 获取账单规则与收费项目关系详细信息
     */
    @GetMapping(value = "/{refId}")
    public AjaxResult getInfo(@PathVariable("refId") Long refId) {
        return success(apartmentItemRuleRefService.selectApartmentItemRuleRefByRefId(refId));
    }

    /**
     * 获取账单规则与收费项目关系详细信息
     */
    @GetMapping(value = "/ruleId/{ruleId}")
    public AjaxResult getInfoByRuleId(@PathVariable("ruleId") Long ruleId) {
        return success(apartmentItemRuleRefService.selectApartmentItemRuleRefByRuleId(ruleId));
    }

    /**
     * 新增账单规则与收费项目关系
     */
    @PostMapping
    public AjaxResult add(@RequestBody @Valid ApartmentItemRuleRef apartmentItemRuleRef) {
        Long orgId = loginUserUtil.getOrgId();
        String id = loginUserUtil.getId();
        apartmentItemRuleRef.setUserId(id);
        apartmentItemRuleRef.setOrgId(orgId);
        return toAjax(apartmentItemRuleRefService.insertApartmentItemRuleRef(apartmentItemRuleRef));
    }

    /**
     * 修改账单规则与收费项目关系
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ApartmentItemRuleRef apartmentItemRuleRef) {
        return toAjax(apartmentItemRuleRefService.updateApartmentItemRuleRef(apartmentItemRuleRef));
    }

    /**
     * 删除账单规则与收费项目关系
     */
    @DeleteMapping("/{refId}")
    public AjaxResult remove(@PathVariable Long refId) {
        return toAjax(apartmentItemRuleRefService.deleteApartmentItemRuleRefByRefId(refId));
    }


}
